<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
 <html>
 <head>
     <title>百度地图自定义控件</title>
     <!-- 导入样式 -->
     <link href="../js/searchbox/searchbox.css" rel="stylesheet" type="text/css" />
     <!-- 导入百度地图API脚本 -->
     <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.1&services=true"></script>
     <!-- 导入控件脚本 -->
     <script type="text/javascript" src="../js/searchbox/searchbox.js"></script>
 
     <style type="text/css">
         #map
         {
             width: 800px;
             height: 500px;
         }
     </style>
 </head>
 <body onload="pageLoad();">
     <div id="map" class="searchbox_casing">
     </div>
 
     <script type="text/javascript">
         var map;
         function pageLoad() {
             var zoom = 14;
             map = new BMap.Map("map");
             map.enableScrollWheelZoom();
             map.addControl(new BMap.NavigationControl());
             map.centerAndZoom(new BMap.Point(113.287967,23.138278), zoom);
                     
             var searchbox = new SearchBox({anchor:BMAP_ANCHOR_TOP_RIGHT});// 创建搜索控件对象，并设置它停靠在地图的右上位置
             searchbox.city = "北京市";// 在北京市查找数据
             searchbox.callback = function(point){// 设置回调函数
                 // 如果找到地址了就在该坐标添加一个标记
                 if(point)
                 {
                     map.centerAndZoom(point, zoom);
                     marker = new BMap.Marker(point);
                     map.addOverlay(marker);
                 }
                 else
                 {
                     alert("没查到数据！");
                 }
             }
             map.addControl(searchbox);  // 将搜索控件添加到地图上
         }
     </script>
 
 </body>
 </html>